//
//  SEGPhoneRechargeViewModel.m
//  SEGViewModel
//
//  Created by 山刘 on 2020/6/1.
//

#import "SEGPhoneRechargeViewModel.h"

@implementation SEGPhoneRechargeViewModel
#pragma mark - business
-(void)segRequestAdvlistWithPositionType:(void(^)(BOOL isSuccessed,NSURL * pic))completed{
    [[SEGAdvlistManager sharedManager] segRequestAdvlistWithPositionType:SEGAdvlistType_DETAILPIC completed:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull codeType, NSString * _Nonnull errorMessage) {
        NSString *str = @"";
        if (isSuccessed) {
            NSArray<SEGAdvertismentModel*> *arr = (NSArray*)result;
            str = [NSString stringWithFormat:@"%@%@", kClientImageRootURL, ValueToString(arr.firstObject.pic)];
        }
        completed(isSuccessed,[NSURL URLWithString:str]);
    }];
}

-(void)requestSubmitPhoneByChargeWithWinId:(NSString *)winId phone:(NSString *)phone completed:(void(^)(NSString* codeType,NSString* errorMessage))completed {
    //提交手机号
    [self.inviteManager requestSubmitPhoneByChargeWithWinId:winId phone:phone finished:^(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage) {
        if ([codeType isEqualToString:@"0"]) {
            self.inviteManager.applyTime = @"暂无";
            //显示完成界面
            if ([result isKindOfClass:[NSDictionary class]] && [result valueForKey:@"data"]) {
                if ([[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]] && [[result valueForKey:@"data"] valueForKey:@"applyTime"]) {
                    self.inviteManager.applyTime = [[result valueForKey:@"data"] valueForKey:@"applyTime"];
                }
            }
            //保存提交状态
            [[NSUserDefaults standardUserDefaults] setObject:self.inviteManager.applyTime forKey:[NSString stringWithFormat:@"isSubmitPhone%@%@",kAccountUserID,winId]];
        }
        completed(codeType,errorMessage);
    }];
}
#pragma mark - getter
- (SEGInviteManager *)inviteManager
{
    if (!_inviteManager) {
        _inviteManager = [[SEGInviteManager alloc] init];
    }
    return _inviteManager;
}
@end
